import { getAreaObj } from '@/utils/util'

export const formConfig = (status) => {
	let tempObj = []
	if (status == 2) {
		tempObj = [
			{
				label: '处理人',
				prop: 'adviserIdCard',
				propName: 'adviserName',
				type: 'autoSelect',
				api: 'view_amAdviser_page',
				filterKey: 'idCard',
				filterLabel: 'adviserName',
        paramsObj:{
          isWithAuth:2
        },
				span: 24,
			},
		]
	}

	return {
		inline: false,
		showBtn: true,
		labelPosition: 'top',
		labelWidth: '120px',
		column: [
			{
				label: '姓名',
				prop: 'name',
				type: 'text',
				span: 12,
				rules: [{ required: true, message: '请输入姓名' }],
			},
			{
				label: '身份证号',
				prop: 'idCard',
				type: 'text',
				span: 12,
				rules: [{ required: true, message: '请输入身份证号' }],
			},
			{
				label: '联系方式',
				prop: 'phone',
				type: 'text',
				span: 12,
				rules: [{ required: true, message: '请输入联系方式' }],
			},

			{
				label: '住址',
				prop: 'address',
				type: 'input',
				span: 12,
			},
			{
				label: '需求',
				prop: 'demand',
				propName: 'demandLabel',
				type: 'remoteSelect',
				code: 'AM_DEMAND',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 24,
			},

			{
				label: '需求简述',
				prop: 'demandDesc',
				type: 'textarea',
				span: 24,
			},
			...tempObj,
		],
	}
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '姓名',
			prop: 'name',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'phone',
			type: 'input',
			span: 8,
		},
		{
			label: '需求',
			prop: 'demand',
			type: 'remoteSelect',
			code: 'AM_DEMAND',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '处理结果',
			prop: 'handleStatus',
			type: 'select',
			dicData: [
				{ label: '待处理', value: '1', type: 'primary' }, // 待认领
				{ label: '处理中', value: '2', type: 'waring' }, // 已认领
				{ label: '已完成', value: '3', type: 'success' }, // 已办结
			],
			span: 8,
		},
		{
			label: '处理时间',
			prop: 'handleTimeBetween',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
		{
			label: '时间',
			prop: 'createTimeBetween',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			type: 'dateBetween',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区域', prop: 'beAreaNames' },
		{ label: '时间', prop: 'createTime' },
		{ label: '姓名', prop: 'name' },
		{ label: '性别', prop: 'genderLabel' },
		{ label: '身份证号', prop: 'idCard' },
		{ label: '联系方式', prop: 'phone' },
		{ label: '住址', prop: 'address' },
		{ label: '需求', prop: 'demandLabel' },
		{
			label: '处理结果',
			prop: 'handleStatus',
			propName: 'handleStatusLabel',
			custome: 'tag',
			dicData: [
				{ label: '待处理', value: '1', type: 'primary' }, // 待认领
				{ label: '处理中', value: '2', type: 'waring' }, // 已认领
				{ label: '已完成', value: '3', type: 'success' }, // 已办结
			],
		},
		{ label: '处理人', prop: 'adviserName' },
		{ label: '处理时间', prop: 'handleTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_amDemandRecord_page',
	add: 'view_amDemandRecord_add',
	edit: 'view_amDemandRecord_edit',
	delete: 'view_amDemandRecord_del',
	detail: 'view_amDemandRecord_view',
	export: 'view_amDemandRecord_export',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '银发顾问服务需求记录',
	dictcodes: ['TRAINING_FORM', 'TRAIN_CONTENT', 'AM_DEMAND'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '认领',
			type: 'primary',
			operate: 'claim',
			auth: auth.edit,
			condition: "(row)=>row.handleStatusLabel =='待处理'",
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '取消认领',
			type: 'primary',
			operate: 'calcel_claim',
			auth: auth.edit,
			condition: "(row)=>row.handleStatusLabel =='处理中'",
			text: true,
			show: true,
		},
		// {
		// 	icon: 'editor',
		// 	label: '编辑',
		// 	type: 'primary',
		// 	operate: 'edit',
		// 	auth: auth.edit,
		// 	text: true,
		// 	show: true,
		// },
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, 'be')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	dialogConfig: {
		width: '55%',
	},
	searchConfig,
	formConfig: formConfig(),
	tableConfig,
	detailConfig: formConfig(),
}
